package com.taru.order.service;



import com.taru.order.common.Data;
import com.taru.order.common.JsonResult;
import com.taru.order.dao.CateDaoImpl;
import com.taru.order.entity.Articl;
import com.taru.order.entity.Category;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;

public class CateServiceImpl  {

    CateDaoImpl cateDao=new CateDaoImpl();


    public List<Category> getCategories()  {

        return cateDao.getCategories();
    }


    public int addCategory(Category category) {

        return cateDao.addCategory(category);
    }


    public int modCategory(Category category)  {

        return cateDao.modCategory(category);
    }


    public int remove(List<Integer> list) throws Exception {

        return cateDao.removeCategories(list);
    }

    public Data listArticls(Integer pageNum,Integer pageSize,String cate_id){
        Integer pNum=(pageNum-1)*pageSize;
        List<Articl> list= cateDao.listImgArticl(pNum,pageSize,cate_id);
        Data data=new Data();
        data.setPageNum(pageNum);
        data.setPageSize(pageSize);
        data.setList(list);
        data.setTotalCount(cateDao.getTotal(cate_id));
        data.setTotalPage(cateDao.getTotal(cate_id),pageSize);
        return data;
    }

    public Articl listArticlOne(String cate_id){

        return cateDao.listArticlOne(cate_id);
    }


    public Data listAllArticls(String cateId, Integer pageNum, Integer pageSize) {
        List<Articl> articlList=cateDao.listAllArticls(cateId,pageNum,pageSize);
        long toralCount=cateDao.queryToral(cateId);
        Data data=new Data();
        data.setTotalCount(toralCount);
        data.setTotalPage(toralCount,pageSize);
        data.setPageNum(pageNum);
        data.setPageSize(pageSize);
        data.setList(articlList);
        return data;
    }

    public  List<Articl> listArticlsByYear(String cateId,String year){

        return cateDao.listArticlsByYear(cateId,year);
    }
    public  List<Articl> listArticlsByMonth(String cateId,String year,String month){

        return cateDao.listArticlsByMonth(cateId,year,month);
    }

}
